import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
  name: 'user',
  initialState: {
    token:'',
    userInfo:{
        name:localStorage.getItem('user')||'' ,
        avatar:localStorage.getItem('avatar')||''
    },
    detail:[]
  },
  reducers: {
     updateData(state,action){
        state.token=action.payload
     
        console.log(action.payload)
     },
     updateUser(state,action){
           state.userInfo.name=action.payload
          
       console.log(action.payload)
     },
     updateImg(state,action){
        state.userInfo.avatar=action.payload
        console.log(action.payload)
     },
     updateDetail(state,action){
      state.detail=action.payload
         console.log(action.payload)
     }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { updateData,updateUser,updateImg,updateDetail } = counterSlice.actions

export default counterSlice.reducer